package app.util.image.action.morph
{
	import app.util.*;
	import app.util.image.*;
	import app.util.image.action.*;
	import app.util.image.calc.*;
	
	import flash.display.*;

	public class DSmoothingAction extends SEBasedAction
	{
		private var progress:Number = 0;
		private var p1:GrayBitmapData;
		private var p2:GrayBitmapData;
		private var ret:GrayBitmapData;
		private var gSrc:GrayBitmapData;
		
		public override function getDescription():String
		{
			return "Dynamic Smoothing";
		}
		
		protected override function getFinalBitmapData():BitmapData
		{
			return this.ret.toBitmapData();
		}
		
		protected override function processBitmapDataByStep():Number
		{
			if(this.progress == 0)
			{
				gSrc = MorphUtility.autoGray(Mediator.getCurrentBitmapData());
				this.p1 = MorphUtility.doGrayDilation(gSrc, se);
				this.progress += 0.25;
			}
			else if(this.progress == 0.25)
			{
				this.p2 = MorphUtility.doGrayErosion(gSrc, se);
				this.progress += 0.25;
			}
			else
			{
				this.ret = p1.add(p2);
				this.progress += 0.5;		
			}
			
			return this.progress;
		}
	}
}